package com.example.onlinemonitoring.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.onlinemonitoring.model.Dlzllsensor;
import com.example.onlinemonitoring.model.Dlzlldssensor;
import com.example.onlinemonitoring.model.Dtssensor;
import com.example.onlinemonitoring.model.Jddlsensor;
import com.example.onlinemonitoring.model.Oilconfig;
import com.example.onlinemonitoring.dao.DlzllconfigMapper;
import com.example.onlinemonitoring.dao.AppalarmMapper;
import com.example.onlinemonitoring.model.Dlzllhistory;
import com.example.onlinemonitoring.model.Appalarm;
import com.example.onlinemonitoring.model.Dlzllconfig;
import com.example.onlinemonitoring.model.common.MyResult;
import com.example.onlinemonitoring.model.common.chartres;
import com.example.onlinemonitoring.model.common.pagebase;
import com.example.onlinemonitoring.query.QueryObject;
import com.example.onlinemonitoring.serviceImpl.DlzllsensorServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import tk.mybatis.mapper.entity.Example;
import java.util.Date;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.Workbook;

/**
 * Controller
 * 该部分代码为自动生成，请勿随意修改
 * 如有改动请删除该注释
 * 
 * @author little pig page
 * @date 2022-03-28
 */
@Api(value = "电缆载流量设备", tags = { "|电缆载流量设备|设备接口" })
@RestController
@RequestMapping("/Cablecurrentcarrying")
public class DlzllsensorController {
    Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
    @Autowired
    DlzllsensorServiceImpl dlzllsensorServiceImpl;
    float currentcarr = 0;
    float θc =40.0f;
    float t =1.0f;

    @ApiOperation(value = "计算静态载流量", notes = "计算静态载流量")
    @ResponseBody
    @RequestMapping(value = "/Calcstaticcurrent", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> Calcstaticcurrent(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        Dlzllsensor record = object.toJavaObject(Dlzllsensor.class);
        MyResult<Integer> m = new MyResult<Integer>();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        currentcarr = dlzllsensorServiceImpl.Calccurrent1(record);
       
        record.setLastcurrentcarr(currentcarr);
      
       // t = dlzllsensorServiceImpl.CalccurrentT(record);
        record.setLastcommunicationstatus(0);
        record.setLastdatatime(new Date());
        record.setLastalarmlevel(0);
        record.setLastalarmmessage("");
        int ret = dlzllsensorServiceImpl.Update(record, false);
        if ( ret>= 1) {
            m.setMsg("修改成功");
            m.setCode(0);
            m.setRet(currentcarr);
        } else {
            //m.setMsg("修改失败");
            //m.setCode(1);
            if (ret == 0) {
                record.setId((long)0);
                dlzllsensorServiceImpl.Add(record);
            }
        } 
        if ( ret< 0)
        {
            m.setMsg("修改失败");
            m.setCode(1);            
        }

        return m;
    }

    @ApiOperation(value = "计算动态载流量", notes = "计算动态载流量")
    @ResponseBody
    @RequestMapping(value = "/Calcdynamiccurrent", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> Calcdynamiccurrent(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        Dlzllsensor record = object.toJavaObject(Dlzllsensor.class);
        MyResult<Integer> m = new MyResult<Integer>();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        θc = dlzllsensorServiceImpl.Calccurrent2(record);
        record.setLaststarttemperature(θc);
        record.setLastcommunicationstatus(0);
        record.setLastdatatime(new Date());
        record.setLastalarmlevel(0);
        record.setLastalarmmessage("");
        if (dlzllsensorServiceImpl.Update(record, false) >= 1) {
            m.setMsg("修改成功");
            m.setCode(0);
            m.setRet(θc);
        } else {
            m.setMsg("修改失败");
            m.setCode(1);
        }
        return m;
    }
    @ApiOperation(value = "计算短时应急负荷θc", notes = "计算短时应急负荷θc")
    @ResponseBody
    @RequestMapping(value = "/Calccurrentθc", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> Calccurrentθc(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        Dlzllsensor record = object.toJavaObject(Dlzllsensor.class);
        MyResult<Integer> m = new MyResult<Integer>();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        θc = dlzllsensorServiceImpl.Calccurrentθc(record);
        record.setLastendtemperature(θc);
        record.setLastcommunicationstatus(0);
        record.setLastdatatime(new Date());
        record.setLastalarmlevel(0);
        record.setLastalarmmessage("");
        if (dlzllsensorServiceImpl.Update(record, false) >= 1) {
            m.setMsg("修改成功");
            m.setCode(0);
            m.setRet(θc);
        } else {
            m.setMsg("修改失败");
            m.setCode(1);
        }
        return m;
    }
    @ApiOperation(value = "计算短时应急负荷T", notes = "计算短时应急负荷T")
    @ResponseBody
    @RequestMapping(value = "/CalccurrentT", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> CalccurrentT(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        Dlzllsensor record = object.toJavaObject(Dlzllsensor.class);
        MyResult<Integer> m = new MyResult<Integer>();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        t = dlzllsensorServiceImpl.CalccurrentT(record);
        if(t<0)
        t=0;

        //Dlzlldssensor ds = object.toJavaObject(Dlzlldssensor.class);
        Dlzlldssensor ds = new Dlzlldssensor();
        ds.setStationid(stationid);
        ds.setDevicegroup(devicegroup);
        ds.setDeviceaddr(deviceaddr);
        ds.setPointaddr(pointaddr);
        int ret = dlzllsensorServiceImpl.Delete(ds);
        for(int i=0;i<t+1;i++)
        {

            record.setLastspantime(i*1f); 
            θc = dlzllsensorServiceImpl.Calccurrentθc(record);
           // if(θc>150)
            //break;
            ds.setStationid(stationid);
            ds.setDevicegroup(devicegroup);
            ds.setDeviceaddr(deviceaddr);
            ds.setPointaddr(pointaddr);
            ds.setLastdlhlcurrent(record.getLastdlhlcurrent()); 
            ds.setLaststartcurrent(record.getLaststartcurrent());
            ds.setLastairtemperature(record.getLastairtemperature());
            ds.setLastendtemperature(θc); 
            ds.setLastspantime(i);
            ds.setLastcommunicationstatus(0);
            ds.setLastdatatime(new Date());
            ds.setLastalarmlevel(0);
            ds.setLastalarmmessage("");
            //int ret = dlzllsensorServiceImpl.Update(ds, false);
            ds.setId((long)0);
            ret = dlzllsensorServiceImpl.Add(ds);
            if ( ret>= 1) {
                m.setMsg("添加成功");
                m.setCode(0);
                m.setRet(θc);
            } else {
                m.setMsg("修改失败");
                m.setCode(1);

            } 
        }

        record.setLastspantime(t); 
        record.setLastendtemperature(θc); 
        record.setLastcommunicationstatus(0);
        record.setLastdatatime(new Date());
        record.setLastalarmlevel(0);
        record.setLastalarmmessage("");
        if (dlzllsensorServiceImpl.Update(record, false) >= 1) {
            m.setMsg("修改成功");
            m.setCode(0);
            m.setRet(t*60);
        } else {
            m.setMsg("修改失败");
            m.setCode(1);
        }
        return m;
    }

    @ApiOperation(value = "修改设备参数", notes = "修改设备参数")
    @ResponseBody
    @RequestMapping(value = "/updateAll", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateAll(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        Dlzllsensor record = object.toJavaObject(Dlzllsensor.class);
        MyResult<Integer> m = new MyResult<Integer>();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        if (dlzllsensorServiceImpl.Update(record, false) >= 1) {
            m.setMsg("修改成功");
            m.setCode(0);
        } else {
            m.setMsg("修改失败");
            m.setCode(1);
        }
        return m;
    }

    @ApiOperation(value = "修改载流量配置参数", notes = "修改载流量配置参数")
    @ResponseBody
    @RequestMapping(value = "/updateAllConfig", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateAllConfig(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        // JSONArray li = JSONArray.parseArray(jsonParam);
        // for (int i = 0; i < li.size(); i++) {
        // JSONObject object = li.getJSONObject(i);
        Dlzllconfig dcfg = object.toJavaObject(Dlzllconfig.class);
        // Dlzllconfig record = new Dlzllconfig();
        dcfg.setStationid(stationid);
        dcfg.setDevicegroup(devicegroup);
        dcfg.setDeviceaddr(deviceaddr);
       // pointaddr = 2;
       dcfg.setPointaddr(pointaddr);

        Dlzllsensor record = new Dlzllsensor();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        record.setPointname(dcfg.getPointname());
        record.setDevicename(dcfg.getDevicename());
        record.setCablecircuit(dcfg.getCablecircuit());
        record.setLastcablephase(dcfg.getCablephase());
        if (dlzllsensorServiceImpl.Update(dcfg, false) == 0) {
            dcfg.setId((long)0);
            dlzllsensorServiceImpl.Add(dcfg);
            
        }
        int ret = dlzllsensorServiceImpl.Update(record, false);
        if (ret==0)
        dlzllsensorServiceImpl.Add(record);
        MyResult<Integer> m = new MyResult<Integer>();
        m.setMsg("修改成功");
        m.setCode(0);
        return m;
    }

    @ApiOperation(value = "查询配置参数", notes = "查询配置参数")
    @ResponseBody
    @GetMapping("/selectConfig")
    public MyResult<Dlzllconfig> selectConfig(
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        Dlzllconfig record = new Dlzllconfig();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        record.setPointaddr(pointaddr);
        return dlzllsensorServiceImpl.getList(record);
    }

    @ApiOperation(value = "修改设备报警", notes = "修改设备报警")
    @ResponseBody
    @RequestMapping(value = "/updateAlarm", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateAlarm(@RequestBody String jsonParam,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        MyResult<Integer> m = new MyResult<Integer>();
        // Dlzllsensor record = object.toJavaObject(Dlzllsensor.class);
        Dlzllsensor record = new Dlzllsensor();
        record.setStationid(stationid);
        record.setDevicegroup(devicegroup);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        if (dlzllsensorServiceImpl.Update(record, false) >= 1) {
            m.setMsg("修改成功");
            m.setCode(0);
        } else {
            m.setMsg("修改失败");
            m.setCode(1);
        }
        return m;
    }

    @ApiOperation(value = "查询实时表数据", notes = "查询实时表数据")
    @ResponseBody
    @GetMapping("/selectSensorData")
    public MyResult<Dlzllsensor> selectSensorData(
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup) {
        Dlzllsensor record = new Dlzllsensor();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        record.setPointaddr(pointaddr);
        QueryObject qo = new QueryObject(page, limit);
        return dlzllsensorServiceImpl.getList(record, qo);
    }
    @ApiOperation(value = "查询短时实时表曲线", notes = "查询短时实时表曲线")
    @ResponseBody
    @GetMapping("/selectDssensorCurve")
    public MyResult<chartres> selectDssensorCurve(
            @RequestParam(value = "limit", required = true) Integer limit,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime,
            @RequestParam(value = "pagecount", required = false) Integer pagecount,
            @RequestParam(value = "lstr", required = false) String lstr) {
            Dlzlldssensor record = new Dlzlldssensor();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        //pagebase.setPage(page);
       // limit = 4000;
        pagebase.setLimit(limit);
        pagebase.setPagecount(pagecount);
        pagebase.setIsasc(true);
        return dlzllsensorServiceImpl.getCurveList(record, lstr);
    }

    @ApiOperation(value = "修改监测点名称", notes = "修改监测点名称")
    @ResponseBody
    @RequestMapping(value = "/updateMonitorName", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public MyResult<Integer> updateMonitorName(@RequestBody String jsonParam,
            @RequestParam(value = "id", required = false) Long id) {
        JSONObject object = JSONObject.parseObject(jsonParam);
        MyResult<Integer> m = new MyResult<Integer>();
        Dlzllsensor record = new Dlzllsensor();
        record.setId(id);
        record.setDevicename(object.getString("devicename"));
        record.setPointname(object.getString("pointname"));
        if (dlzllsensorServiceImpl.Update(record, true) >= 1) {
            m.setMsg("修改成功");
            m.setCode(0);
        } else {
            m.setMsg("修改失败");
            m.setCode(1);
        }
        return m;
    }

    @ApiOperation(value = "查询历史表数据", notes = "查询历史表数据")
    @ResponseBody
    @GetMapping("/selectHistoryData")
    public MyResult<Dlzllhistory> selectHistoryData(
            @RequestParam(value = "page", required = true) Integer page,
            @RequestParam(value = "limit", required = true) Integer limit,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime,
            @RequestParam(value = "pagecount", required = false) Integer pagecount) {
        Dlzllhistory record = new Dlzllhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        pagebase.setPage(page);
        pagebase.setLimit(limit);
        pagebase.setPagecount(pagecount);
        return dlzllsensorServiceImpl.getHisList(record, pagebase);
    }

    @ApiOperation(value = "查询历史表曲线", notes = "查询历史表曲线")
    @ResponseBody
    @GetMapping("/selectHistoryCurve")
    public MyResult<chartres> selectHistoryCurve(
            @RequestParam(value = "page", required = true) Integer page,
            @RequestParam(value = "limit", required = true) Integer limit,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr,
            @RequestParam(value = "pointaddr", required = false) Integer pointaddr,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime,
            @RequestParam(value = "pagecount", required = false) Integer pagecount,
            @RequestParam(value = "lstr", required = false) String lstr) {
        Dlzllhistory record = new Dlzllhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setPointaddr(pointaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        pagebase.setPage(page);
       // limit = 4000;
        pagebase.setLimit(limit);
        pagebase.setPagecount(pagecount);
        pagebase.setIsasc(true);
        return dlzllsensorServiceImpl.getHisCurveList(record, lstr, pagebase);
    }

    /**
     * 导出Excel
     */
    @GetMapping("exportToExcel")
    public void exportToExcel(HttpServletResponse response,
            @RequestParam(value = "stationid", required = true) Integer stationid,
            @RequestParam(value = "devicegroup", required = true) Integer devicegroup,
            @RequestParam(value = "deviceaddr", required = true) Integer deviceaddr,
            @RequestParam(value = "start", required = false) String begintime,
            @RequestParam(value = "end", required = false) String endtime) throws IOException {
        Dlzllhistory record = new Dlzllhistory();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        pagebase pagebase = new pagebase();
        pagebase.setBegintime(begintime);
        pagebase.setEndtime(endtime);
        Workbook wb = dlzllsensorServiceImpl.writeToExcelByList(record, pagebase);
        OutputStream output = response.getOutputStream();
        String fileName = "data.xlsx";
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setHeader("Content-disposition",
                "attachment;filename=" + fileName + ";" + "filename*=utf-8''" + fileName);
        wb.write(output);
        output.close();
    }

    /**
     * 导出Excel
     */
    @GetMapping("exportToSensorExcel")
    public void exportToSensorExcel(HttpServletResponse response,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr) throws IOException {
        Dlzllsensor record = new Dlzllsensor();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        Workbook wb = dlzllsensorServiceImpl.writeToExcelBySensorList(record);
        OutputStream output = response.getOutputStream();
        String fileName = "data.xlsx";
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setHeader("Content-disposition",
                "attachment;filename=" + fileName + ";" + "filename*=utf-8''" + fileName);
        wb.write(output);
        output.close();
    }
    /**
     * 导出Excel
     */
    @GetMapping("exportToDssensorExcel")
    public void exportToDssensorExcel(HttpServletResponse response,
            @RequestParam(value = "stationid", required = false) Integer stationid,
            @RequestParam(value = "devicegroup", required = false) Integer devicegroup,
            @RequestParam(value = "deviceaddr", required = false) Integer deviceaddr) throws IOException {
        Dlzlldssensor record = new Dlzlldssensor();
        record.setStationid(stationid);
        record.setDeviceaddr(deviceaddr);
        record.setDevicegroup(devicegroup);
        Workbook wb = dlzllsensorServiceImpl.writeToExcelBySensorList(record);
        OutputStream output = response.getOutputStream();
        String fileName = "data.xlsx";
        try {
            fileName = URLEncoder.encode(fileName, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        response.setHeader("Content-disposition",
                "attachment;filename=" + fileName + ";" + "filename*=utf-8''" + fileName);
        wb.write(output);
        output.close();
    }
}
